<template>
  <el-container>
    <el-aside
      ><el-header><h1>今日热播</h1></el-header>
      <el-main class="top-bg">
        <el-card
          :body-style="{ padding: '0px' }"
          @click="cardclick(firstmovie.mid)"
        >
          <div class="card-content">
            <img :src="firstmovie.img_url" class="image" />
            <div class="title-bg">
              <span class="title">{{ firstmovie.chinese_name }}</span>
            </div>
          </div>
        </el-card>
      </el-main>
    </el-aside>
    <el-container>
      <el-main>
        <el-carousel :interval="4000" type="card" height="280px"  v-loading="loading"
               element-loading-text="Loading...">
          <el-carousel-item v-for="item in pictureInfo" :key="item.id"  >
            <img
              :src="item.pictureurl"
              class="image"
            />
          </el-carousel-item>
        </el-carousel>
        <el-container
          ><el-header class="title-head"><h2>推荐影片</h2></el-header
          ><el-main class="top-main">
            <el-row>
              <el-col
                v-for="(o, index) in moviedata"
                :key="o"
                :span="4"
                :offset="index > 0 ? 2 : 2"
              >
                <el-card
                  :body-style="{ padding: '0px' }"
                  @click="cardclick(o.mid)"
                >
                  <div class="card-content">
                    <img :src="o.img_url" class="image" />
                    <div class="title-bg">
                      <span class="title">{{ o.chinese_name }}</span>
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row></el-main
          >
          <el-header><h2>即将上映</h2></el-header
          ><el-main class="top-main">
            <el-row>
              <el-col
                v-for="(o, index) in expectMovie"
                :key="o"
                :span="4"
                :offset="index > 0 ? 2 : 2"
              >
                <el-card
                  :body-style="{ padding: '0px' }"
                  @click="cardclick(o.mid)"
                >
                  <div class="card-content">
                    <img :src="o.img_url" class="image" />
                    <div class="title-bg">
                      <span class="mask">期待中...</span>
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row></el-main
          >
        </el-container>
      </el-main>
    </el-container>

    <el-aside class="top-aside"
      ><el-header><h1>排行榜</h1></el-header>
      <el-main class="top-mains">
        <el-table style="width: 100%" :data="toplist">
          <el-table-column label="Top" width="80"
            ><template #default="scope"
              ><span>{{ scope.$index + 1 }}</span>
              <span class="topbg" v-if="scope.$index==0">
                <img src="../../assets/images/hm.png"></span></template
            ></el-table-column
          >
          <el-table-column prop="chinese_name" label="影片名" width="150" />
          <el-table-column prop="rating" label="评分" width="100" />
        </el-table>
      </el-main>

      <el-header><h1>最受期待</h1></el-header>
      <el-main class="top-mains">
        <el-table style="width: 100%" :data="expectTop">
            <el-table-column label="Top" width="80"
            ><template #default="scope"
              ><span>{{ scope.$index + 1 }}</span>
              <span class="topbg" v-if="scope.$index==0">
                <img src="../../assets/images/lh.png"></span></template
            ></el-table-column>
          <el-table-column prop="chinese_name" label="影片名" width="150" />
          <el-table-column prop="rating" label="评分" width="100" />
        </el-table>
      </el-main>
    </el-aside>
  </el-container>
</template>
<script lang="ts">
import { computed, onMounted, reactive, ref ,onBeforeMount} from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
export default {
  setup() {
    const routers = useRouter();
    const store = useStore();
    onMounted(()=>{
      loadInfo();
    })
    // onBeforeMount(() => {
    //  loadInfo();
    // });
    const loading=ref(true);
    const toplist = computed(()=>{ return store.state.movie.movieTopList});
    const expectTop=computed(()=>{ return store.state.movie.expectTopMovie});
    /**排行榜加载 */
    const loadInfo = () => {
      store.dispatch("SET_MOVIETOP");
      store.dispatch("SET_MOVIELIST");
      setTimeout(()=>{
         store.dispatch("SET_PICTUREINFO",store.state.movie.movieTopList[0].mid);
         loading.value=false;
      },1000)
    };
    const pictureInfo = computed(() => {
      return store.state.picture. pictureInfo;
    });
    const firstmovie = computed(() => {
      return store.state.movie.movieTopList[0];
    });
    const moviedata = computed(() => {
      return store.state.movie.movieList;
    });
    const expectMovie=computed(()=>{
      return  store.state.movie.expectMovie;
    })
    const cardclick = (id: any) => {
      routers.push({ path: "/info" });
      store.dispatch("SET_MOVIEINFO", id);
      store.dispatch("SET_DISCUSSINFO",id);
      store.dispatch("SET_PICTUREINFO",id);
    };
    return {
      moviedata,
      expectMovie,
      routers,
      cardclick,
      toplist,
      firstmovie,
      expectTop,
      pictureInfo,
      loading,
    };
  },
};
</script>
<style scoped>
.title-head {
  min-width: 128px;
}
.top-main {
  padding: 0;
  overflow: hidden;
  min-width: 500px;
}
.top-mains {
  padding: 0;
  overflow: hidden;
  margin-bottom: 30px;
}
.top-bg {
  margin: 0 10px;
}
.topbg img{
  height: 30px;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-col-4 {
  margin-bottom: 20px;
}
.el-aside {
  width: 15%;
  min-width: 200px;
}
.top-aside {
  width: 20%;
}
.top-header {
  margin: 0;
  padding: 0;
}
.images {
  width: 100%;
  display: block;
}
.image {
  width: 100%;
  display: block;
}
.card-content {
  position: relative;
}
.title-bg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
background: url()
    repeat-x bottom;
}  
.title {
  font-size: 14px;
  position: absolute;
  left: 0;
  bottom: 0;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 2px;
  color: #fff;
}
.el-card:hover {
  box-shadow: -10px 0 8px rgb(0, 0, 0, 0.5);
}
.el-footer {
  padding: 0;
}
.foot {
  flex-direction: column;
  background: #262426;
  padding: 56px 0;
}
.foot p {
  text-align: center;
  color: #ccc;
  height: 22px;
  line-height: 22px;
  font-size: 14px;
}
h2 {
  overflow: hidden;
  display: inline-block;
}
.mask{
  position: absolute;
  left: 0;
  bottom: 20px;
  width: 100%;
  line-height: 50px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: black;
  color: #fff;
  text-align: center;
  opacity: 0.6;
}
</style>